<?php

namespace app\commands\crontab;

use app\commission\Commission;
use app\models\user\UserCommission;
use yii\console\Controller;

/**
 * Class MonthAwardController
 * @package app\commands\crontab
 */
class MonthAwardController extends Controller
{
    // php yii crontab/month-award/index
    // 30 4 1 * * php yii crontab/month-award/index
    // 30 4 1 * * php /root/zhao/api/yii crontab/month-award/index
    // 每月1号4点30分执行
    public function actionIndex()
    {
        $list = UserCommission::find()
            ->where(['month_return' => 1])
            ->andWhere(['status' => 0])
            ->all();

        $now = date('Ym', time());
        foreach ($list as $item) {
            $month = date('Ym', strtotime($item->create_time));
            if ($now - $month >= 1) {
                $item->status = 1;
                $item->save();

                Commission::getInstance()->commissionSaveAccount($item);
                // echo $item->id, ' ok ....', "\n";
            }
        }
    }
}